/*
 * 
 * 
 */

package DigimonAdventure.Things;

import DigimonAdventure.Database.DigimonSpecies;
import DigimonAdventure.Database.Armor;
import DigimonAdventure.Database.Weapon;
import DigimonAdventure.Database.Shield;
import DigimonAdventure.Database.Boost;
import DigimonAdventure.Database.Acc;
import javax.swing.ImageIcon;

/**
 *
 * @author Kris Derril Siregar
 */
public final class DigimonBaik extends AbstractDigimon{
    private Armor Armor;
    private Weapon Weapon;
    private Shield Shield;
    private Boost Boost;
    private Acc Acc;
	private int trainPoint;
    private int exp;

	public DigimonBaik(int posX,int posY,DigimonSpecies species,int str,int vit,int res,int agi){
        super(posX,posY,species, str, vit, res, agi);
        trainPoint = 1;
        exp = 0;
        Weapon = Weapon.None;
        Armor = Armor.None;
        Shield = Shield.None;
        Boost = Boost.None;
        Acc = Acc.None;
        strata = this.getStrata();
    }
    /**
     * buat bayi baru maka dibutuhkan spesiesnya
     * status dasar sudah ditetapkan dari spesiesnya
     * equip isinya none semua
     * posisi juga berada di origin
     * @param species
     */
    public DigimonBaik(DigimonSpecies species) {
        super(0,0,species,0, 0, 0, 0);
        //inisialisasi status digimon
        trainPoint = 1;
        exp = 0;
        Weapon = Weapon.None;
        Armor = Armor.None;
        Shield = Shield.None;
        Boost = Boost.None;
        Acc = Acc.None;
        strata = strata.getStrata(level);
        
     }
    /**
     *
     */
    public void addLife(int x){
        Life += x;
        if (Life > HP){
            Life = HP;
        }
    }
    /**
     * Mengembalikan senjata sang digimon.
     * Mengembalikan Weapon.none jika sang digimon tidak memiliki senjata
     * @return
     */
    public Weapon getWeapon(){
        if(Weapon == null){
            return Weapon.None;
        }else{
            return Weapon;
        }
    }
    public Armor getArmor(){
        if(Armor == null){
            return Armor.None;
        }else{
            return Armor;
        }
    }
    public Shield getShield(){
        if(Shield ==null){
            return Shield.None;
        }else{
            return Shield;
        }
    }
    public Boost getBoost(){
        if(Boost == null){
            return Boost.None;
        }else{
            return Boost;
        }
    }
    public Acc getAcc(){
        if(Acc == null){
            return Acc.None;
        }else{
            return Acc;
        }
    }
    /**
     * Speciesnya masih belum berubah, cuma strata sama stat yang berubah
     */
    public void doEvolve(){
        switch(level){
            case 2: species = DigimonSpecies.valueOf(species.getNextEvolution());
                    strata = strata.getStrata(level);
                    vit += species.getBaseVit();
                    str += species.getBaseStr();
                    res += species.getBaseRes();
                    agi += species.getBaseAgi();
                    break;
            case 5: species = DigimonSpecies.valueOf(species.getNextEvolution());
                    strata = strata.getStrata(level);
                    vit += DigimonSpecies.valueOf(species.getNextEvolution()).getBaseVit();
                    str += DigimonSpecies.valueOf(species.getNextEvolution()).getBaseStr();
                    res += DigimonSpecies.valueOf(species.getNextEvolution()).getBaseRes();
                    agi += DigimonSpecies.valueOf(species.getNextEvolution()).getBaseAgi();
                    break;
        }
    }

    public void addExp (int exp){
        if(this.exp + exp >= 100){
            this.exp = 100;
        }else {this.exp += exp;}
    levelUp();
    }
    public int getExp(){
        return exp;
    }
    public int getTP(){
        return trainPoint;
    }
    public int getLv(){
        return level;
    }
        
     /**
      * Mengeset HP digimon yang telah dipengaruhi equipment
      */

    public void EquipArmor(Armor A){
        HP += A.getModV();
        att += A.getModS();
        def += A.getModR();
        eva += A.getModA();
        Armor = A;
    }
    public void RemoveArmor(Armor A){
        HP -= A.getModV();
        att -= A.getModS();
        def -= A.getModR();
        eva -= A.getModA();
        Armor = Armor.None;
    }

    public void EquipWeapon(Weapon A){
        HP += A.getModV();
        att += A.getModS();
        def += A.getModR();
        eva += A.getModA();
        Weapon = A;
    }
    public void RemoveWeapon(Weapon A){
        HP -= A.getModV();
        att -= A.getModS();
        def -= A.getModR();
        eva -= A.getModA();
        Weapon = Weapon.None;
    }
    public void EquipShield(Shield A){
        HP += A.getModV();
        att += A.getModS();
        def += A.getModR();
        eva += A.getModA();
        Shield = A;
    }
    public void RemoveShield(Shield A){
        HP -= A.getModV();
        att -= A.getModS();
        def -= A.getModR();
        eva -= A.getModA();
        Shield = Shield.None;
    }
    public void EquipBoost(Boost A){
        HP += A.getModV();
        att += A.getModS();
        def += A.getModR();
        eva += A.getModA();
        Boost = A;
    }
    public void RemoveBoost(Boost A){
        HP -= A.getModV();
        att -= A.getModS();
        def -= A.getModR();
        eva -= A.getModA();
        Boost = Boost.None;
    }
    public void EquipAcc(Acc A){
        HP += A.getModV();
        att += A.getModS();
        def += A.getModR();
        eva += A.getModA();
        Acc = A;
    }
    public void RemoveAcc(Acc A){
        HP -= A.getModV();
        att -= A.getModS();
        def -= A.getModR();
        eva -= A.getModA();
        Acc = Acc.None;
    }

    public void trainStr(){
        if (trainPoint > 0){
            trainPoint--;
            addStr(5);
        }
    }
    public void trainVit(){
        if (trainPoint > 0){
            trainPoint--;
            addVit(10);
        }
    }
    public void trainRes(){
        if (trainPoint > 0){
            trainPoint--;
            addRes(5);
        }
    }
    public void trainAgi(){
        if (trainPoint > 0){
            trainPoint--;
            addAgi(5);
        }
    }
    
    public static void main(String [] args ){

    }

    private void levelUp() {
        if(exp == 100){
            if(level < 10){
                exp =0;
                trainPoint += 1;
                level += 1;
                att += (str * strata.getMul());
                def += (res * strata.getMul());
                eva += (agi * strata.getMul());
                HP += (vit * strata.getMul());
                doEvolve();
            }else if(level == 10){
                exp = 100;
                level += 1;
                att += (str * strata.getMul());
                def += (res * strata.getMul());
                eva += (agi * strata.getMul());
                HP += (vit * strata.getMul());
            }else {exp = 100;}
        }        
    }

}
